package org.vaadinetherealintegration.client.example3;

import etrl.geometry.Drawable;
import etrl.geometry.IndexArray;
import etrl.geometry.PrimitiveKind;
import etrl.geometry.Vertex;
import etrl.geometry.VertexArray;
import etrl.vecmath.Vector2f;
import etrl.vecmath.Vector3f;
import etrl.vecmath.Vector4f;

public class Block extends Drawable
{

	public Block()
	{
		super(PrimitiveKind.TRIANGLES);
		
		Vector4f color = new Vector4f(1.0f, 1.0f, 1.0f, 1.f);
		
		// == LEFT
		Vertex v1 = new Vertex();
		v1._coordinate = new Vector4f(-0.5f, -0.5f, 0.5f, 1.0f);
		v1._color = color;
		v1._normal = new Vector3f(-1.0f, 0.0f, 0.0f);
		v1._texCoord = new Vector2f(0.f, 0.f);
		
		Vertex v2 = new Vertex();
		v2._coordinate = new Vector4f(-0.5f, -0.5f, -0.5f, 1.0f);
		v2._color = color;
		v2._normal = new Vector3f(-1.0f, 0.0f, 0.0f);
		v2._texCoord = new Vector2f(1.f, 0.f);
		
		Vertex v3 = new Vertex();
		v3._coordinate = new Vector4f(-0.5f, 0.5f, -0.5f, 1.0f);
		v3._color = color;
		v3._normal = new Vector3f(-1.0f, 0.0f, 0.0f);
		v3._texCoord = new Vector2f(1.f, 1.f);
		
		Vertex v4 = new Vertex();
		v4._coordinate = new Vector4f(-0.5f, 0.5f, 0.5f, 1.0f);
		v4._color = color;
		v4._normal = new Vector3f(-1.0f, 0.0f, 0.0f);
		v4._texCoord = new Vector2f(0.f, 1.f);
		
		// == RIGHT
		Vertex v5 = new Vertex();
		v5._coordinate = new Vector4f(0.5f, -0.5f, -0.5f, 1.0f);
		v5._color = color;
		v5._normal = new Vector3f(1.0f, 0.0f, 0.0f);
		v5._texCoord = new Vector2f(0.f, 0.f);
		
		Vertex v6 = new Vertex();
		v6._coordinate = new Vector4f(0.5f, -0.5f, 0.5f, 1.0f);
		v6._color = color;
		v6._normal = new Vector3f(1.0f, 0.0f, 0.0f);
		v6._texCoord = new Vector2f(1.f, 0.f);
		
		Vertex v7 = new Vertex();
		v7._coordinate = new Vector4f(0.5f, 0.5f, 0.5f, 1.0f);
		v7._color = color;
		v7._normal = new Vector3f(1.0f, 0.0f, 0.0f);
		v7._texCoord = new Vector2f(1.f, 1.f);
		
		Vertex v8 = new Vertex();
		v8._coordinate = new Vector4f(0.5f, 0.5f, -0.5f, 1.0f);
		v8._color = color;
		v8._normal = new Vector3f(1.0f, 0.0f, 0.0f);
		v8._texCoord = new Vector2f(0.f, 1.f);
		
		// == TOP
		Vertex v9 = new Vertex();
		v9._coordinate = new Vector4f(-0.5f, 0.5f, 0.5f, 1.0f);
		v9._color = color;
		v9._normal = new Vector3f(0.0f, 1.0f, 0.0f);
		v9._texCoord = new Vector2f(0.f, 0.f);
		
		Vertex v10 = new Vertex();
		v10._coordinate = new Vector4f(0.5f, 0.5f, 0.5f, 1.0f);
		v10._color = color;
		v10._normal = new Vector3f(0.0f, 1.0f, 0.0f);
		v10._texCoord = new Vector2f(1.f, 0.f);
		
		Vertex v11 = new Vertex();
		v11._coordinate = new Vector4f(0.5f, 0.5f, -0.5f, 1.0f);
		v11._color = color;
		v11._normal = new Vector3f(0.0f, 1.0f, 0.0f);
		v11._texCoord = new Vector2f(1.f, 1.f);
		
		Vertex v12 = new Vertex();
		v12._coordinate = new Vector4f(-0.5f, 0.5f, -0.5f, 1.0f);
		v12._color = color;
		v12._normal = new Vector3f(0.0f, 1.0f, 0.0f);
		v12._texCoord = new Vector2f(0.f, 1.f);
		
		// == FRONT
		Vertex v13 = new Vertex();
		v13._coordinate = new Vector4f(-0.5f, -0.5f, 0.5f, 1.0f);
		v13._color = color;
		v13._normal = new Vector3f(0.0f, 0.0f, 1.0f);
		v13._texCoord = new Vector2f(0.f, 0.f);
		
		Vertex v14 = new Vertex();
		v14._coordinate = new Vector4f(0.5f, -0.5f, 0.5f, 1.0f);
		v14._color = color;
		v14._normal = new Vector3f(0.0f, 0.0f, 1.0f);
		v14._texCoord = new Vector2f(1.f, 0.f);
		
		Vertex v15 = new Vertex();
		v15._coordinate = new Vector4f(0.5f, 0.5f, 0.5f, 1.0f);
		v15._color = color;
		v15._normal = new Vector3f(0.0f, 0.0f, 1.0f);
		v15._texCoord = new Vector2f(1.f, 1.f);
		
		Vertex v16 = new Vertex();
		v16._coordinate = new Vector4f(-0.5f, 0.5f, 0.5f, 1.0f);
		v16._color = color;
		v16._normal = new Vector3f(0.0f, 0.0f, 1.0f);
		v16._texCoord = new Vector2f(0.f, 1.f);
		
		// == BACK
		Vertex v17 = new Vertex();
		v17._coordinate = new Vector4f(-0.5f, -0.5f, -0.5f, 1.0f);
		v17._color = color;
		v17._normal = new Vector3f(0.0f, 0.0f, -1.0f);
		v17._texCoord = new Vector2f(0.f, 0.f);
		
		Vertex v18 = new Vertex();
		v18._coordinate = new Vector4f(0.5f, -0.5f, -0.5f, 1.0f);
		v18._color = color;
		v18._normal = new Vector3f(0.0f, 0.0f, -1.0f);
		v18._texCoord = new Vector2f(1.f, 0.f);
		
		Vertex v19 = new Vertex();
		v19._coordinate = new Vector4f(0.5f, 0.5f, -0.5f, 1.0f);
		v19._color = color;
		v19._normal = new Vector3f(0.0f, 0.0f, -1.0f);
		v19._texCoord = new Vector2f(1.f, 1.f);
		
		Vertex v20 = new Vertex();
		v20._coordinate = new Vector4f(-0.5f, 0.5f, -0.5f, 1.0f);
		v20._color = color;
		v20._normal = new Vector3f(0.0f, 0.0f, -1.0f);
		v20._texCoord = new Vector2f(0.f, 1.f);
		
		VertexArray vertexArray = new VertexArray();
		vertexArray.push_back(v1);
		vertexArray.push_back(v2);
		vertexArray.push_back(v3);
		vertexArray.push_back(v4);
		vertexArray.push_back(v5);
		vertexArray.push_back(v6);
		vertexArray.push_back(v7);
		vertexArray.push_back(v8);
		vertexArray.push_back(v9);
		vertexArray.push_back(v10);
		vertexArray.push_back(v11);
		vertexArray.push_back(v12);
		vertexArray.push_back(v13);
		vertexArray.push_back(v14);
		vertexArray.push_back(v15);
		vertexArray.push_back(v16);
		vertexArray.push_back(v17);
		vertexArray.push_back(v18);
		vertexArray.push_back(v19);
		vertexArray.push_back(v20);
		
		
		IndexArray indexArray = new IndexArray();
		// == LEFT
		indexArray.push_back(0);
		indexArray.push_back(1);
		indexArray.push_back(2);
		indexArray.push_back(0);
		indexArray.push_back(2);
		indexArray.push_back(3);
	
		// == RIGHT
		indexArray.push_back(4);
		indexArray.push_back(5);
		indexArray.push_back(6);
		indexArray.push_back(4);
		indexArray.push_back(6);
		indexArray.push_back(7);
		
		// == TOP
		indexArray.push_back(8);
		indexArray.push_back(9);
		indexArray.push_back(10);
		indexArray.push_back(8);
		indexArray.push_back(10);
		indexArray.push_back(11);
		
		// == FRONT
		indexArray.push_back(12);
		indexArray.push_back(13);
		indexArray.push_back(14);
		indexArray.push_back(12);
		indexArray.push_back(14);
		indexArray.push_back(15);
		
		// == BACK
		indexArray.push_back(16);
		indexArray.push_back(17);
		indexArray.push_back(18);
		indexArray.push_back(16);
		indexArray.push_back(18);
		indexArray.push_back(19);

		setVertexArray(vertexArray);
		setIndexArray(indexArray);
		
		//addTexture("brick.jpg", true);
	}

}
